package com.ruoyi.web.controller.stock;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.TransactOperaReplay;
import com.ruoyi.stock.service.ITransactOperaReplayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 今日操作复盘Controller
 *
 * @author ruoyi
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/stock/replay")
public class TransactOperaReplayController extends BaseController {
    @Autowired
    private ITransactOperaReplayService transactOperaReplayService;

    /**
     * 查询今日操作复盘列表
     */
    @PreAuthorize("@ss.hasPermi('stock:replay:list')")
    @GetMapping("/list")
    public TableDataInfo list(TransactOperaReplay transactOperaReplay) {
        startPage();
        List<TransactOperaReplay> list = transactOperaReplayService.selectTransactOperaReplayList(transactOperaReplay);
        return getDataTable(list);
    }

    /**
     * 导出今日操作复盘列表
     */
    @PreAuthorize("@ss.hasPermi('stock:replay:export')")
    @Log(title = "今日操作复盘", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TransactOperaReplay transactOperaReplay) {
        List<TransactOperaReplay> list = transactOperaReplayService.selectTransactOperaReplayList(transactOperaReplay);
        ExcelUtil<TransactOperaReplay> util = new ExcelUtil<TransactOperaReplay>(TransactOperaReplay.class);
        util.exportExcel(response, list, "今日操作复盘数据");
    }

    /**
     * 获取今日操作复盘详细信息
     */
    @PreAuthorize("@ss.hasPermi('stock:replay:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(transactOperaReplayService.selectTransactOperaReplayById(id));
    }

    /**
     * 新增今日操作复盘
     */
    @PreAuthorize("@ss.hasPermi('stock:replay:add')")
    @Log(title = "今日操作复盘", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransactOperaReplay transactOperaReplay) {
        return toAjax(transactOperaReplayService.insertTransactOperaReplay(transactOperaReplay));
    }

    /**
     * 修改今日操作复盘
     */
    @PreAuthorize("@ss.hasPermi('stock:replay:edit')")
    @Log(title = "今日操作复盘", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransactOperaReplay transactOperaReplay) {
        return toAjax(transactOperaReplayService.updateTransactOperaReplay(transactOperaReplay));
    }

    /**
     * 删除今日操作复盘
     */
    @PreAuthorize("@ss.hasPermi('stock:replay:remove')")
    @Log(title = "今日操作复盘", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(transactOperaReplayService.deleteTransactOperaReplayByIds(ids));
    }
}
